/**
 * Created by enroll on 2018/6/24.
 */
import { HttpService, HTTPMethods } from "http-service";
import { Injectable } from "@angular/core";
import { API } from "../../models/api-path-extension";
import { ResponseData } from "../../models/response-data";
import { Observable } from "rxjs/Observable";
import { ResponseDistrict, ResponseDistricts } from "../../models/response/response-districts";
import { ResponseUsers } from "../../models/response/response-user";
import { ResponseWorkOrders } from "../../models/response/response-work-order";
import { SystemUser } from "../../models/system-user";
import { CurdService } from "../../models/services/curd.service";
import { UserDto } from "../../models/dto/user.dto";
import { User } from "../../models/transform/user";
import { DistrictDto } from "../../models/dto/district.dto";
import { District } from "../../models/transform/district";
import { SysUserDto } from "../../models/dto/sysUser.dto";
import { SysUser } from "../../models/transform/sysUser";
import { WorkOrderDto } from "../../models/dto/work-orders.dto";
import { WorkOrder } from "../../models/transform/work-order";
import { StorageDto } from "../../models/dto/storage.dto";
import { CustomStorage } from "../../models/transform/custom-storage";
import { BillDto } from "../../models/dto/bill.dto";
import { Bill } from "../../models/transform/bill";
import { AreaDto } from "../../models/dto/area.dto";
import { Area } from "../../models/transform/area";
import { DeviceDto } from "../../models/dto/device.dto";
import { Device } from "../../models/transform/device";
import { ObjectDto } from "../sqliteDB/object.dto";
import { UpdateBillService } from "./update-bill.service";

@Injectable()
export class UpdateWorkOrderService {
  customStorageData: Array<object>;

  constructor(
    private httpService: HttpService,
    public curdService: CurdService,
    public updateBillService: UpdateBillService) {

  }

  updateApply(result) {
    result.data.forEach((item, index) => {
      // item["applyId"] = item.applyId;
      this.curdService.update({
        dto: WorkOrderDto,
        mapObj: WorkOrder
      }, item, {
          and: [{
            id: item.applyId,
            orderNo: item.orderNo
          }]
        }).then((res) => {
          if (index === result.data.length - 1) {
            this.updateBillService.getPayHistory();
            // console.log(index, "----");
          }
        });
    });
  }



}
